#include <bits/stdc++.h>
using namespace std;
#define int long long

const int p = 998244353;
int n, a[5005], frc[200005], inv[200005];

long long qpow(long long a, long long b) {
	long long res = 1;
	while (b) {
		if (b & 1) res = res * a % p;
		b >>= 1;
		a = a * a % p;
	}
	return res;
}

namespace CR200J {
	set<vector<char>> tmp;
	void dfs(vector<char> a) {
		if (tmp.find(a) != tmp.end()) return;
		tmp.insert(a);
		for (int i = 1; i < n; ++i) {
			if (a[i] != a[i - 1]) {
				int tmp = max(a[i], a[i - 1]);
				int yi = a[i], yi1 = a[i - 1];
				a[i] = a[i - 1] = tmp;
				dfs(a);
				a[i] = yi; a[i - 1] = yi1;
			}
		}
	}
	void main() {
		vector<char> init;
		for (int i = 1; i <= n; ++i) init.push_back(a[i]);
		dfs(init);
		cout << tmp.size() << "\n";
	}
}

namespace CRH3 {
	void main() {
		cout << frc[2 * n] * inv[n] % p * inv[n] % p * qpow(n + 1, p - 2) % p << "\n"; 
	}
}

signed main() {
	freopen("after.in", "r", stdin); freopen("after.out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	frc[0] = frc[1] = inv[0] = inv[1] = 1;
	for (int i = 2; i <= 200000; ++i) {
		frc[i] = frc[i - 1] * i % p;
		inv[i] = (p - p / i) * inv[p % i] % p;
	}
	for (int i = 2; i <= 200000; ++i) {
		(inv[i] *= inv[i - 1]) %= p;
	}
	cin >> n;
	int flg = 1;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		flg &= (a[i] >= a[i - 1]);
	}
	if (n <= 8) CR200J::main();
	else if (flg) CRH3::main();
	else ;
	return 0;
}
